<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        文章编辑
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">

    <link rel="stylesheet" href="/static/css/x-admin.css" media="all">


    <!--百度编辑器-->
    <script src="/static/ueditor/ueditor.config.js"></script>
    <script src="/static/ueditor/ueditor.all.min.js"></script>
    <script src="/static/ueditor/lang/zh-cn/zh-cn.js"></script>
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>轮播管理</cite></a>
              <a><cite>编辑轮播</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form layui-form-pane" action="" id="add">
        <div class="layui-tab layui-tab-brief" lay-filter="docDemoTabBrief">
            <ul class="layui-tab-title">
                <li class="layui-this">基本信息</li>
            </ul>

            <div class="layui-tab-content" >
                <div class="layui-tab-item layui-show">
                    <!--<form class="layui-form layui-form-pane" action="" id="add">-->
                    <input type="hidden" name="id" value="{$info.id}">
                    <div class="layui-form-item">
                        <label for="link" class="layui-form-label">
                            <span class="x-red">*</span>缩略图
                        </label>
                        <div class="layui-input-inline">
                            <input type="file" name="photo" class="layui-upload-file" >
                            <input type="hidden" name="img" id="img" value="{$info.img}">
                        </div>
                        <div class="layui-form-mid layui-word-aux">
                            <img src="{$info.img}" style="max-width: 100px" id="photos" alt=""  >
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="link" class="layui-form-label">
                            <span class="x-red">*</span>地址
                        </label>
                        <div class="layui-input-block">
                            <input type="text" name="link" autocomplete="off" value="{$info.link}" placeholder="链接地址"
                                   class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label for="link" class="layui-form-label">
                            <span class="x-red">*</span>位置
                        </label>
                        <div class="layui-input-block">
                            <select name="position" id="article_category_id">
                                {if condition="$info.position eq 1"}
                                <option value="1" selected>首页标题</option>
                                <option value="2">banner轮播</option>
                                <option value="3">首页资讯</option>
                                {/if}
                                {if condition="$info.position eq 2"}
                                <option value="1">首页标题</option>
                                <option value="2" selected>banner轮播</option>
                                <option value="3">首页资讯</option>
                                {/if}
                                {if condition="$info.position eq 3"}
                                <option value="1">首页标题</option>
                                <option value="2">banner轮播</option>
                                <option value="3" selected>首页资讯</option>
                                {/if}
                            </select>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <button class="layui-btn" type="button" lay-filter="add" lay-submit="">
                            保存
                        </button>
                    </div>
                    <!--</form>-->
                    <div style="height:100px;"></div>
                </div>
            </div>

        </div>
    </form>
</div>
<script src="/static/lib/layui/layui.js" charset="utf-8"></script>
<script src="/static/js/x-layui.js" charset="utf-8"></script>
<script type="text/javascript">
    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    UE.getEditor('content',{initialFrameWidth:600,initialFrameHeight:400,});
</script>
<script>
    layui.use(['element','layer','form','upload'], function(){
        $ = layui.jquery;//jquery
        lement = layui.element();//面包导航
        layer = layui.layer;//弹出层
        form = layui.form();
        layui.upload({
            url: '{:url("upload")}'
            ,success: function(res){
                $('#img').val('/storage/'+res.imgpath);
                $('#photos').attr('src','/storage/'+res.imgpath);
            }
        });


        //监听提交
        form.on('submit(add)', function(data){
            var jkl= {
                id:data.field.id,
                img:data.field.img,
                link:data.field.link,
                position:data.field.position
            };
            if(jkl['img']=="")
            {
                layer.msg('上传图片不能为空',{icon:5,time:2000});return false;
            }
            if(jkl['link']=="")
            {
                layer.msg('链接地址不能为空',{icon:5,time:2000});return false;
            }
            if(jkl['position']=="")
            {
                layer.msg('位置不能为空',{icon:5,time:2000});return false;
            }
            $.ajax({
                type:"post",
                url:"{:url('bannerUpdates')}",
                data:jkl,
                success:function (res) {
                    if (res.code==100){
                        layer.msg(res.msg, {icon: 6,time:2000},function () {
                            window.parent.location.reload();
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.layer.close(index);
                        });
                        return false;
                    }else{
                        layer.msg(res.msg, {icon: 7,time:2000});
                        return false;
                    }
                }

            });

        });

    })
</script>
</body>
</html>